using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace OurWedding1.Models
{ 
    public class PlaceTypeRepository : IPlaceTypeRepository
    {
        WeddingEntities context = new WeddingEntities();

        public IQueryable<PlaceType> All
        {
            get { return context.PlaceTypes; }
        }

        public IQueryable<PlaceType> AllIncluding(params Expression<Func<PlaceType, object>>[] includeProperties)
        {
            IQueryable<PlaceType> query = context.PlaceTypes;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public PlaceType Find(int id)
        {
            return context.PlaceTypes.Find(id);
        }

        public void InsertOrUpdate(PlaceType placetype)
        {
            if (placetype.PlaceTypeId == default(int)) {
                // New entity
                context.PlaceTypes.Add(placetype);
            } else {
                // Existing entity
                context.Entry(placetype).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var placetype = context.PlaceTypes.Find(id);
            context.PlaceTypes.Remove(placetype);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IPlaceTypeRepository : IDisposable
    {
        IQueryable<PlaceType> All { get; }
        IQueryable<PlaceType> AllIncluding(params Expression<Func<PlaceType, object>>[] includeProperties);
        PlaceType Find(int id);
        void InsertOrUpdate(PlaceType placetype);
        void Delete(int id);
        void Save();
    }
}